﻿using System;
using System.Collections.Generic;
using System.Web;

namespace TraditionalMalteseCuisine.App_Code.Functions
{
    public class DateTime_Functions
    {
        //*************************************************
        //                   Methods
        //*************************************************
        #region Methods
        public static int CountNumberOfMonths(DateTime d1, DateTime d2)
        {
            int no_of_months = 1;

            no_of_months += (d2.Year - d1.Year) * 12;

            no_of_months += (d2.Month - d1.Month);

            return no_of_months;
        }

        public static bool IsSmaller(DateTime d1, DateTime d2)
        {
            return (DateTime.Compare(d1, d2) < 0);
        }

        public static bool IsGreater(DateTime d1, DateTime d2)
        {
            return (DateTime.Compare(d1, d2) > 0);
        }

        public static bool IsEqual(DateTime d1, DateTime d2)
        {
            return (DateTime.Compare(d1, d2) == 0);
        }


        public static DateTime GetFirstOfMonthFormat(DateTime d)
        {
            return DateTime.Parse(string.Format("01-{0}-{1:0000}", GetShortMonthName(d.Month), d.Year.ToString()));
        }


        public static string GetMonthYearFormat(DateTime d)
        {
            return string.Format("{0} {1:0000}", GetFullMonthName(d.Month), d.Year.ToString());
        }

        public static string GetLongDate(string d)
        {
            DateTime vdate = DateTime.Parse(d);

            d = string.Format("{0:00} {1} {2:0000}", vdate.Day, GetFullMonthName(vdate.Month), vdate.Year);

            return d;
        }

        public static string GetShortDate(string d)
        {
            DateTime vdate = DateTime.Parse(d);

            d = string.Format("{0:00}-{1}-{2:0000}", vdate.Day, GetShortMonthName(vdate.Month), vdate.Year);

            return d;
        }

        public static string GetShortDate(DateTime d)
        {
            return d.ToString("dd-MMM-yyyy");
        }

        public static string GetShortDateTime(DateTime d)
        {
            return d.ToString("dd-MMM-yyyy HH:mm:ss");
        }

        public static string GetShortMonthName(int month)
        {
            return GetShortMonthName(GetFullMonthName(month));
        }

        public static string GetShortMonthName(string month)
        {
            return month.Substring(0, 3);
        }

        public static string GetDayNumber(int day)
        {
            switch (day)
            {
                case 1:
                    return "1st";
                case 2:
                    return "2nd";
                case 3:
                    return "3rd";
                case 21:
                    return "21st";
                case 22:
                    return "22nd";
                case 23:
                    return "23rd";
                case 31:
                    return "31st";
                default:
                    return String.Format("{0}th", day);
            }
        }

        public static string GetFullMonthName(int month)
        {
            switch (month)
            {
                case 1:
                    return "January";
                case 2:
                    return "February";
                case 3:
                    return "March";
                case 4:
                    return "April";
                case 5:
                    return "May";
                case 6:
                    return "June";
                case 7:
                    return "July";
                case 8:
                    return "August";
                case 9:
                    return "September";
                case 10:
                    return "October";
                case 11:
                    return "November";
                case 12:
                    return "December";
                default:
                    return "";
            }
        }

        public static string GetFullMonthName(string month)
        {
            switch (month)
            {
                case "Jan":
                    return GetFullMonthName(1);
                case "Feb":
                    return GetFullMonthName(2);
                case "Mar":
                    return GetFullMonthName(3);
                case "Apr":
                    return GetFullMonthName(4);
                case "May":
                    return GetFullMonthName(5);
                case "Jun":
                    return GetFullMonthName(6);
                case "Jul":
                    return GetFullMonthName(7);
                case "Aug":
                    return GetFullMonthName(8);
                case "Sep":
                    return GetFullMonthName(9);
                case "Oct":
                    return GetFullMonthName(10);
                case "Nov":
                    return GetFullMonthName(11);
                case "Dec":
                    return GetFullMonthName(12);
                default:
                    return "";
            }
        }
        #endregion
        //*************************************************
    }
}